package com.un.ebs.product.controller;

import com.un.ebs.core.util.WebResult;
import com.un.ebs.core.util.WebUtils;
import com.un.ebs.product.domain.ProductSkuFillExt;
import com.un.ebs.product.dto.ProductSkuFillAddDto;
import com.un.ebs.product.dto.ProductSkuFillUpdateDto;
import com.un.ebs.product.service.ProductSkuFillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author liubo
 * @email liubocs@163.com
 * @date 2020/2/19 19:01
 */
@RestController
@RequestMapping("/productSkuFill")
@Api(value = "product-sku-fill", description = "商品sku库存投放")
public class ProductSkuFillController {

    @Autowired
    private ProductSkuFillService service;

    @PostMapping("add")
    @ApiOperation(value = "添加一笔新的投放记录")
    public WebResult<String> add(@RequestBody @Validated ProductSkuFillAddDto req) {
        return WebUtils.success(service.add(req));
    }

    @PostMapping("update")
    @ApiOperation(value = "修改投放记录")
    public WebResult update(@RequestBody @Validated ProductSkuFillUpdateDto req) {
        service.update(req);
        return WebUtils.success();
    }

    @DeleteMapping("{id}")
    @ApiOperation(value = "删除投放记录")
    public WebResult delete(@PathVariable String id) {
        service.delete(id);
        return WebUtils.success();
    }

    @GetMapping("{id}")
    @ApiOperation(value = "查询投放记录详情")
    public WebResult<ProductSkuFillExt> queryById(@PathVariable String id) {
        return WebUtils.success(service.queryViewById(id));
    }

    @GetMapping("/sku/{skuId}")
    @ApiOperation(value = "根据skuId")
    public WebResult<ProductSkuFillExt> queryViewBySku(@PathVariable String skuId) {
        return WebUtils.success(service.queryView(skuId));
    }

    @GetMapping("/spu/{spuId}")
    @ApiOperation("根据spuId查询所有投放记录")
    public WebResult<ProductSkuFillExt> queryViewBySpu(@PathVariable String spuId) {
        return WebUtils.success(service.queryViewBySpu(spuId));
    }

}
